package com.example.demo.controller;

import com.example.demo.model.User;
import com.example.demo.utils.JacksonUtils;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.Date;


/**
 * Created by Administrator on 2018/4/1.
 */
@RestController
public class TestController {

    @RequestMapping(value = "/feign/provider/user/save", method = RequestMethod.POST, produces = "application/json")
    @ResponseBody
    public String userSave(@Valid @RequestBody User user) {
        user.setCreateTime(new Date());
        System.out.println("feign provider userSave method action,user: " + JacksonUtils.beanToJson(user));
        return JacksonUtils.beanToJson(user);
    }

    @RequestMapping(value = "/feign/provider/user/{id}", method = RequestMethod.GET, produces = "application/json")
    @ResponseBody
    public String getUserById(@PathVariable("id") Integer id) {
        System.out.println("feign provider getUserById method action,id: " + id);
        return JacksonUtils.beanToJson(new User(id, "qwer", "12456", new Date()));
    }

}
